#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    m_pPwd = new QLineEdit(this);
    m_pBtnOK = new QPushButton("OK");
    m_pVBLGlobal = new QVBoxLayout;
    m_pVBLGlobal->addWidget(m_pPwd);
    m_pVBLGlobal->addWidget(m_pBtnOK);

    ui->centralWidget->setLayout(m_pVBLGlobal);

    connect(m_pBtnOK,SIGNAL(clicked()),this,SLOT(onBtnOkClicked()));
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::onBtnOkClicked()
{
    QRegExp exp;

    QString pwd = m_pPwd->text();
    exp.setPatternSyntax(QRegExp::RegExp);
    //对大小写字母敏感，即区分大小写
    exp.setCaseSensitivity(Qt::CaseSensitive);
    //匹配格式为所有大小写字母和数字组成的字符串，8-18位
    exp.setPattern(QString("^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,16}$"));

    if(!exp.exactMatch(pwd)){
        qDebug() << " password format wrong ";
    }else{
        qDebug() << " password format right ";
    }
}
